package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/break-a-palindrome/description/?envType=problem-list-v2&envId=GT3MFwwC
 * @create 2025/10/3 22:03
 * @since JDK17
 */

public class Solution50 {
    public String breakPalindrome(String palindrome) {
        char[] s = palindrome.toCharArray();
        int n = s.length;
        if (n == 1) {
            return "";
        }
        for (int i = 0; i < n; i++) {
            if (s[i] != 'a' && i != n / 2) {
                s[i] = 'a';
                return new String(s);
            }
        }
        s[n - 1] = 'b';
        return new String(s);
    }
}
